#ifndef FORMKEYBOARD_H
#define FORMKEYBOARD_H

#include <QWidget>
#include <QPushButton>
#include <QLineEdit>
#include <QPointer>  // 👈 新增：安全指针

typedef struct {
    int mode;
    int capa;   // 大写锁定
    int opened; // 是否已打开
} key_board_t;

namespace Ui {
class FormKeyBoard;
}

class FormKeyBoard : public QWidget
{
    Q_OBJECT

public:
    explicit FormKeyBoard(QWidget *parent = nullptr, QLineEdit* input = nullptr);
    ~FormKeyBoard();

    void setInputLineEdit(QLineEdit *input);
    int isOpend();
    void Close();
    void keyBoard_mode(int mode);

signals:
    void formkeyboard_close_signal();

private slots:
    void on_pushButton_clicked();          // Del 键（实际由 btn_keyBoard_clicked 处理）
    void btn_keyBoard_clicked(uint8_t index);
    void on_pushButton_30_clicked();       // 关闭按钮

private:
    void delay_ms(unsigned int ms);

    Ui::FormKeyBoard *ui;
    QPointer<QLineEdit> inputObj;  // 👈 安全指针，自动置 null 若对象销毁
    QPushButton *btn_obj[30];

    key_board_t key_board_info = {0, 0, 0};
};

#endif // FORMKEYBOARD_H
